<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>10个常见的 Kubernetes 陷阱和挑战 | 架构成长指南</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
    <meta name="description" content="java技术分享，系统架构剖析，java实践分享，ai相关知识分享，chatGPT,架构成长指南">
  
  
    <meta name="keywords" content="架构成长指南，架构，java，云原生，chatGPT">
  
  
    <link rel="alternate" href="/atom.xml" title="架构成长指南" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
  
    
<link rel="stylesheet" href="/localshare/css/share.css">

  
  
    
<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">

  
  
<meta name="generator" content="Hexo 7.0.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">架构成长指南</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        
          <a class="main-nav-link" href="/."><i class="fa fa-home"></i> 首页</a>
        
          <a class="main-nav-link" href="/archives/"><i class="fa fa-archive"></i> 归档</a>
        
          <a class="main-nav-link" href="/about/"><i class="fa fa-user"></i> 关于</a>
        
      </nav>
    </div>
    <div id="search-form">
      <div id="result-mask" class="hide"></div>
      <label><input id="search-key" type="text" autocomplete="off" placeholder="搜索"></label>
      <div id="result-wrap" class="hide">
        <div id="search-result"></div>
      </div>
      <div class="hide">
        <template id="search-tpl">
          <div class="item">
            <a href="/{path}" title="{title}">
              <div class="title">{title}</div>
              <div class="time">{date}</div>
              <div class="tags">{tags}</div>
            </a>
          </div>
        </template>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-2023/云原生/10个常见的 Kubernetes 陷阱和挑战" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      10个常见的 Kubernetes 陷阱和挑战
    </h1>
  


      </header>
    
    <div class="article-meta">
      
        <span class='article-top'>【置顶】</span>
      
      <span class="article-date">
  <i class="fa fa-date"></i>
  <time class="dt-published" datetime="2023-12-17T04:40:55.190Z" itemprop="datePublished">2023年12月17日</time>
</span>
      
  <div class="article-category">
    <i class="fa fa-classify"></i>
    <a class="article-category-link" href="/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/">云原生</a>
  </div>

      
        <span class="article-views">
  <i class="fa fa-views"></i>
  <i id="busuanzi_container_page_pv">
      <i id="busuanzi_value_page_pv"></i>
  </i>
</span>

      
      
<a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/10%E4%B8%AA%E5%B8%B8%E8%A7%81%E7%9A%84%20Kubernetes%20%E9%99%B7%E9%98%B1%E5%92%8C%E6%8C%91%E6%88%98/#comments" class="article-comment-link">
  
    
    
    
    
    
  
  <i class="fa fa-commt"></i>
  留言
</a>


    </div>
    <div class="e-content article-entry" itemprop="articleBody">
      
        <blockquote>
<p>公众号「架构成长指南」，专注于生产实践、云原生、分布式系统、大数据技术分享</p>
</blockquote>
<p><img src="https://wz-blogimg.oss-cn-beijing.aliyuncs.com/img/8d89180b-c146-44f1-9f9d-393d70628d5f.png"><br>Kubernetes 是最流行的容器编排和部署平台。它的强大功能特性，可以保障在生产中可靠地运行容器化应用程序。</p>
<p>然而，有灵活性的同时也带来了复杂性，在本文中，我们将探讨许多团队遇到的 10个常见 Kubernetes 陷阱。能够识别并避免这些挑战将提高应用程序的可扩展性、可靠性和安全性，同时让你更好地控制集群及其部署。</p>
<span id="more"></span>

<h4 id="1-使用-latest-Tag-部署容器"><a href="#1-使用-latest-Tag-部署容器" class="headerlink" title="1.使用 latest Tag 部署容器"></a>1.使用 <code>latest</code> Tag 部署容器</h4><p>可以说，Kubernetes 最常被违反的最佳实践之一就是在部署容器时使用latest标签。这将使我们面临无意中接收重大变更的风险，而这些变更可能影响系统稳定性。</p>
<p>每个人使用 latest 标签的方式各不相同，但大多数人都会将 latest 指向其项目的最新版本。例如，今天使用 helm:latest 将提供 Helm v3，但在v4版本发布后，重启就会更新到v4，但是我们可能还认为系统运行的是 v3 版本，从而引发不可预知的风险。</p>
<h4 id="2-不使用Liveness和Readiness-探针"><a href="#2-不使用Liveness和Readiness-探针" class="headerlink" title="2.不使用Liveness和Readiness 探针"></a>2.不使用Liveness和Readiness 探针</h4><p>探针可以使我们的应用程序更具弹性。它们会告知 Kubernetes Pod 的健康状况。</p>
<p>当容器出现问题时，比如内存溢出，Liveness探针请求超时，那么Liveness探针会通知 Kubernetes 重启容器。</p>
<p>有时候应用会暂时性地无法为请求提供服务。 例如，应用在启动时可能需要加载大量的数据或配置文件，或是启动后要依赖等待外部服务。 在这种情况下，既不想杀死应用，也不想给它发送请求。 Kubernetes 提供了Readiness探针来发现并缓解这些情况，容器所在 Pod 上报还未就绪的信息，并且不接受通过 Kubernetes Service 的流量。</p>
<p>下面是一个包含有效性和就绪性探针的简单 Pod：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Pod</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">probes-demo</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">containers:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">probes-demo</span></span><br><span class="line">      <span class="attr">image:</span> <span class="string">nginx:latest</span></span><br><span class="line">      <span class="attr">livenessProbe:</span></span><br><span class="line">        <span class="attr">httpGet:</span></span><br><span class="line">          <span class="attr">path:</span> <span class="string">/</span></span><br><span class="line">          <span class="attr">port:</span> <span class="number">80</span></span><br><span class="line">      <span class="attr">readinessProbe:</span></span><br><span class="line">        <span class="attr">httpGet:</span></span><br><span class="line">          <span class="attr">path:</span> <span class="string">/</span></span><br><span class="line">          <span class="attr">port:</span> <span class="number">80</span>           </span><br></pre></td></tr></table></figure>

<h4 id="3-缺少节点选择器导致调度效率低下"><a href="#3-缺少节点选择器导致调度效率低下" class="headerlink" title="3. 缺少节点选择器导致调度效率低下"></a>3. 缺少节点选择器导致调度效率低下</h4><p>集群的整体性能取决于 Pod 是否被正确调度到合适的节点上。许多集群包含多种类型的节点，例如用于标准应用程序的小型 <code>2 CPU/4 GB</code>节点和用于密集后端服务的较大<code>8 CPU/16GB</code>节点。</p>
<p>如果Pod无法可靠地调度到我们想要的节点池，那么集群利用率将会很低。例如即使有未充分利用的较小节点，也会强制创建不必要的新的较大节点，从而增加集群的成本。通过在节点上设置标签，然后使用节点选择器将每个 Pod 分配给兼容的节点来避免此问题：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Pod</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">pod-node-selector-demo</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">containers:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">nginx</span></span><br><span class="line">      <span class="attr">image:</span> <span class="string">nginx:latest</span></span><br><span class="line">  <span class="attr">nodeSelector:</span></span><br><span class="line">    <span class="attr">node-class:</span> <span class="string">2vcpu4gb</span></span><br></pre></td></tr></table></figure>

<p>此 Pod 只会调度到设置了标签的节点<strong>node-class: 2vcpu4gb</strong></p>
<p>使用命令在匹配的节点上设置标签：<code>kubectl label</code></p>
<p><img src="https://wz-blogimg.oss-cn-beijing.aliyuncs.com/img/bdd65e2d-a23c-46ea-adfb-463bcc212d2b.png"><br>设置适当的调度规则将最大限度地提高节点利用率并保持稳定的集群性能。</p>
<h4 id="4-破坏-Pod-亲和性-反亲和性规则"><a href="#4-破坏-Pod-亲和性-反亲和性规则" class="headerlink" title="4.破坏 Pod 亲和性&#x2F;反亲和性规则"></a>4.破坏 Pod 亲和性&#x2F;反亲和性规则</h4><p>Pod 亲和性和反亲和性规则允许指示 Kubernetes 哪个节点最适合部署Pod。规则可以以节点级特征（例如标签）或已在节点上运行的其他 Pod 的特征为条件。</p>
<p>亲和性规则将Pod吸引到 Node，使得 Pod 更有可能调度到特定Node上，而反亲和性则具有排斥作用，降低了调度的概率。 Kubernetes 会评估每个可用于调度的可能节点的 Pod 亲和性规则，然后选择最合适的一个。</p>
<p>亲和力系统能够支持复杂的调度行为，但也很容易错误配置亲和力规则，Pod会意外地调度到不正确的节点，或者拒绝调度。</p>
<p>比如一个服务的两个副本，应该调度在两个Node上，这样如果一个 Node 节点发生故障时，可以保证服务的另一个副本可用，如果规则设置不正确都调度到一个Node 上那么会导致服务不可用。</p>
<h4 id="5-没有监控-记录"><a href="#5-没有监控-记录" class="headerlink" title="5. 没有监控&#x2F;记录"></a>5. 没有监控&#x2F;记录</h4><p>当在Kubernetes 中扩容应用程序时，了解集群资源利用率、应用程序错误和实时性能数据至关重要。内存消耗激增、Pod 驱逐和容器崩溃都是我们应该了解的问题，但标准 Kubernetes不具备任何可观测性功能，以便在故障发生时发出告警。</p>
<p>要启用对集群的监控，我们应该部署可观测性平台，例如 Prometheus、夜莺。这会从 Kubernetes 收集指标，同时在Grafana查看相关数据指标。同时也有告警机制。</p>
<h4 id="6-标签选择器不匹配"><a href="#6-标签选择器不匹配" class="headerlink" title="6. 标签选择器不匹配"></a>6. 标签选择器不匹配</h4><p> 部署和服务等对象依赖正确的标签选择器来识别 Pod 及其管理的其他对象。选择器与实际分配给对象的标签之间的不匹配将导致部署失败。</p>
<p>示例</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">apps/v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Deployment</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">demo-deployment</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">replicas:</span> <span class="number">2</span></span><br><span class="line">  <span class="attr">selector:</span></span><br><span class="line">    <span class="attr">matchLabels:</span></span><br><span class="line">      <span class="attr">app:</span> <span class="string">nginx-demo-app</span></span><br><span class="line">  <span class="attr">template:</span></span><br><span class="line">    <span class="attr">metadata:</span></span><br><span class="line">      <span class="attr">labels:</span></span><br><span class="line">        <span class="comment"># Label does not match the deployment&#x27;s selector!</span></span><br><span class="line">        <span class="attr">app:</span> <span class="string">nginx-demo-application</span></span><br><span class="line">    <span class="attr">spec:</span></span><br><span class="line">      <span class="attr">containers:</span></span><br><span class="line">        <span class="attr">name:</span> <span class="string">nginx-demo-app</span></span><br><span class="line">        <span class="attr">image:</span> <span class="string">nginx:latest</span></span><br></pre></td></tr></table></figure>
<p>以上文件部署会抛出<code>selector does not match template labelsspec.selector.matchLabelsspec.template.metadata.labels</code>要解决此问题，请调整清单的 和 字段，使它们具有相同的键值对</p>
<h4 id="7-服务端口不匹配"><a href="#7-服务端口不匹配" class="headerlink" title="7. 服务端口不匹配"></a>7. 服务端口不匹配</h4><p>同样，确保Service将流量路由到Pod上的正确端口也很重要。不正确的端口定义可能会使 Pod 看起来像是发生了故障，而实际上流量根本没有到达该 Pod。</p>
<p>以下清单包含此问题的示例。该Service监听9000端口并将流量转发到其 Pod上的8080端口 ，但容器实际上端口是80，所以流量无法到达。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Pod</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">demo-pod</span></span><br><span class="line">  <span class="attr">labels:</span></span><br><span class="line">    <span class="attr">app:</span> <span class="string">demo-app</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">image:</span> <span class="string">nginx:latest</span></span><br><span class="line">  <span class="attr">ports:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">containerPort:</span> <span class="number">80</span></span><br><span class="line"></span><br><span class="line"><span class="meta">---</span></span><br><span class="line"><span class="meta"></span></span><br><span class="line"><span class="attr">apiVersion:</span> <span class="string">v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Service</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">demo-service</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">ports:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">port:</span> <span class="number">9000</span></span><br><span class="line">      <span class="attr">protocol:</span> <span class="string">TCP</span></span><br><span class="line">      <span class="attr">targetPort:</span> <span class="number">8080</span></span><br><span class="line">  <span class="attr">selector:</span></span><br><span class="line">    <span class="attr">app:</span> <span class="string">demo-app</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="8-意外部署到错误的命名空间"><a href="#8-意外部署到错误的命名空间" class="headerlink" title="8. 意外部署到错误的命名空间"></a>8. 意外部署到错误的命名空间</h4><p>Kubernetes命名空间将一组服务逻辑分组在一起，在集群中提供一定程度的隔离。为每个团队、应用和环境创建命名空间可以防止名称冲突并简化管理体验。</p>
<p>使用命名空间时，请记住为每个服务和Kubectl命令指定目标命名空间。否则，将使用默认命名空间default。如果服务没有部署在合适的命名空间下，会导致相关服务器请求不可达。</p>
<p>以下清单为Istio Ingress转发配置，此文件部署在seg空间下，然后根据<code>/dp-manager</code>请求，转发到seg空间下的dp-manager-backend服务，如果dp-manager-backend不在<br>seg空间下，那么会导致请求异常。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">apiVersion: networking.istio.io/v1beta1</span><br><span class="line">kind: VirtualService</span><br><span class="line">metadata:</span><br><span class="line">  name: dp-manager-vs</span><br><span class="line">  namespace: seg</span><br><span class="line">spec:</span><br><span class="line">  gateways:</span><br><span class="line">    - dp-manager-gateway</span><br><span class="line">  hosts:</span><br><span class="line">    - control-dpmanager.test.com</span><br><span class="line">  http:</span><br><span class="line">    - match:</span><br><span class="line">        - uri:</span><br><span class="line">            prefix: /dp-manager</span><br><span class="line">      route:</span><br><span class="line">        - destination:</span><br><span class="line">            host: dp-manager-backend</span><br><span class="line">            port:</span><br><span class="line">              number: 80</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="9-没有资源请求和限制的-Pod"><a href="#9-没有资源请求和限制的-Pod" class="headerlink" title="9. 没有资源请求和限制的 Pod"></a>9. 没有资源请求和限制的 Pod</h4><p>正确的资源管理对于保持集群的稳定性至关重要。Pod默认没有任何资源限制，除非我们对其进行配置，因此这可能会导致Node节点CPU 和内存耗尽。</p>
<p>在所有 Pod 上设置适当的资源请求和限制以减少资源争用。请求Kubernetes为我们的 Pod 预留特定数量的资源，防止其调度到无法提供足够容量的节点上。Limits设置Pod可以使用的最大资源量；超过 CPU 限制的 Pod 将受到限制，而达到内存限制则会提示内存不足 (OOM) 从而终止 Pod 允许。</p>
<p>请求和限制在 Pod 清单的 字段中定义：<code>spec.container.resources</code>,</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">v1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">Pod</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line">  <span class="attr">name:</span> <span class="string">demo-pod</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="attr">containers:</span></span><br><span class="line">    <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">demo-container</span></span><br><span class="line">      <span class="attr">image:</span> <span class="string">nginx:latest</span></span><br><span class="line">      <span class="attr">resources:</span></span><br><span class="line">        <span class="attr">requests:</span></span><br><span class="line">          <span class="attr">cpu:</span> <span class="string">100m</span></span><br><span class="line">          <span class="attr">memory:</span> <span class="string">1Gi</span></span><br><span class="line">        <span class="attr">limits:</span></span><br><span class="line">          <span class="attr">memory:</span> <span class="string">2Gi</span></span><br></pre></td></tr></table></figure>
<p>以上Pod 请求100m（1000m等于1核）CPU 时间和 1Gi 内存。它只会调度到可以提供足够资源的节点上。 Pod 还设置了内存限制，最大可以申请2Gi 内存。 最佳实践是将 Pod 的内存限制设置为等于其请求。通常不需要 CPU 限制，因为 Kubernetes 会按比例限制超出其请求的 Pod。</p>
<h4 id="10-集群自动扩容错误"><a href="#10-集群自动扩容错误" class="headerlink" title="10. 集群自动扩容错误"></a>10. 集群自动扩容错误</h4><p>选择Kubernetes原因之一就是它的弹性扩容。正确配置可以使Kubernetes在需求高峰时自动添加新的 Pod 和节点，从而动态的水平和垂直扩容。但是不幸的是，很多团队它们的自动扩容是不可预测的。</p>
<p>因此定期检查集群的利用率，以检查它是否仍然适合您的工作负载。使用负载测试工具（例如Locust）测试自动扩缩规则，将多余的流量引导至集群。这可以使我们更早地发现问题，确保Pod 在实际流量到达时能够无缝扩容。</p>

        
            <div id="toc-article">
                
  <div class="widget-wrap" id="toc-wrap">
    <h3 class="widget-title"><i class="fa fa-toc"></i> 文章目录</h3>
    <div class="widget">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E4%BD%BF%E7%94%A8-latest-Tag-%E9%83%A8%E7%BD%B2%E5%AE%B9%E5%99%A8"><span class="toc-text">1.使用 latest Tag 部署容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E4%B8%8D%E4%BD%BF%E7%94%A8Liveness%E5%92%8CReadiness-%E6%8E%A2%E9%92%88"><span class="toc-text">2.不使用Liveness和Readiness 探针</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E7%BC%BA%E5%B0%91%E8%8A%82%E7%82%B9%E9%80%89%E6%8B%A9%E5%99%A8%E5%AF%BC%E8%87%B4%E8%B0%83%E5%BA%A6%E6%95%88%E7%8E%87%E4%BD%8E%E4%B8%8B"><span class="toc-text">3. 缺少节点选择器导致调度效率低下</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E7%A0%B4%E5%9D%8F-Pod-%E4%BA%B2%E5%92%8C%E6%80%A7-%E5%8F%8D%E4%BA%B2%E5%92%8C%E6%80%A7%E8%A7%84%E5%88%99"><span class="toc-text">4.破坏 Pod 亲和性&#x2F;反亲和性规则</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-%E6%B2%A1%E6%9C%89%E7%9B%91%E6%8E%A7-%E8%AE%B0%E5%BD%95"><span class="toc-text">5. 没有监控&#x2F;记录</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6-%E6%A0%87%E7%AD%BE%E9%80%89%E6%8B%A9%E5%99%A8%E4%B8%8D%E5%8C%B9%E9%85%8D"><span class="toc-text">6. 标签选择器不匹配</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7-%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%8F%A3%E4%B8%8D%E5%8C%B9%E9%85%8D"><span class="toc-text">7. 服务端口不匹配</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8-%E6%84%8F%E5%A4%96%E9%83%A8%E7%BD%B2%E5%88%B0%E9%94%99%E8%AF%AF%E7%9A%84%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4"><span class="toc-text">8. 意外部署到错误的命名空间</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9-%E6%B2%A1%E6%9C%89%E8%B5%84%E6%BA%90%E8%AF%B7%E6%B1%82%E5%92%8C%E9%99%90%E5%88%B6%E7%9A%84-Pod"><span class="toc-text">9. 没有资源请求和限制的 Pod</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#10-%E9%9B%86%E7%BE%A4%E8%87%AA%E5%8A%A8%E6%89%A9%E5%AE%B9%E9%94%99%E8%AF%AF"><span class="toc-text">10. 集群自动扩容错误</span></a></li></ol>
    </div>
  </div>


            </div>
        
        
          <blockquote id="copyright">
              <p>原文链接: <a href="https://dongweizhao.github.io/2023/12/17/2023/云原生/10个常见的 Kubernetes 陷阱和挑战/">https://dongweizhao.github.io/2023/12/17/2023/云原生/10个常见的 Kubernetes 陷阱和挑战/</a></p>
              <p>版权声明: 转载请注明出处.</p>
          </blockquote>
        
      
    </div>
    <footer class="article-footer">
      
        <div class="article-tag-wrap">
          

          
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Kubernetes/" rel="tag">Kubernetes</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/k8s/" rel="tag">k8s</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/k8s10-%E4%B8%AA%E5%B8%B8%E8%A7%81%E6%8C%91%E6%88%98%E5%92%8C%E9%99%B7%E9%98%B1/" rel="tag">k8s10 个常见挑战和陷阱</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E6%9E%B6%E6%9E%84%E6%88%90%E9%95%BF%E6%8C%87%E5%8D%97/" rel="tag">架构成长指南</a></li></ul>

          
    <div class="social-share">
      <span>分享到:</span>
    </div>



        </div>
      
      
        
<nav id="article-nav">
  
    <a href="/2023/11/23/2023/%E5%B7%A5%E5%85%B7/poe%E5%88%86%E4%BA%AB/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">older</strong>
      <div class="article-nav-title">
        
          免费稳定几乎无门槛，我的ChartGPT助手免费分享给你
        
      </div>
    </a>
  
  
    <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/%E5%A6%82%E4%BD%95%E5%9F%BA%E4%BA%8E%20k8s%E5%81%9A%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">newer</strong>
      <div class="article-nav-title">
        
          如何基于 k8s做私有化部署
        
      </div>
    </a>
  
</nav>

      
      
        








      
    </footer>
  </div>
</article>
</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-posts"></i> 最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/%E5%9F%BA%E4%BA%8EK8S%E7%A7%81%E6%9C%89%E5%8C%96%E4%BA%A4%E4%BB%98%E8%A6%81%E6%B3%A8%E6%84%8F%E5%87%A0%E7%82%B9%E9%97%AE%E9%A2%98/">基于K8S私有化交付要注意几点问题</a>
          </li>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/%E4%BB%8E%E7%89%A9%E7%90%86%E6%9C%BA%E5%88%B0K8S%EF%BC%9A%E5%BA%94%E7%94%A8%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2%E6%96%B9%E5%BC%8F%E7%9A%84%E6%BC%94%E8%BF%9B%E5%8F%8A%E5%85%B6%E5%BD%B1%E5%93%8D/">从物理机到K8S：应用系统部署方式的演进及其影响</a>
          </li>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/%E4%BB%80%E4%B9%88%E6%98%AF%E9%9D%A9%E5%91%BD%E6%80%A7%E6%8A%80%E6%9C%AFeBPF%EF%BC%9F%E4%B8%BA%E4%BB%80%E4%B9%88%E5%8F%AF%E8%A7%82%E6%B5%8B%E6%80%A7%E9%A2%86%E5%9F%9F%E9%83%BD%E5%BE%97%E7%94%A8%E5%AE%83/">什么是革命性技术eBPF？为什么可观测性领域都得用它</a>
          </li>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/%E5%A6%82%E4%BD%95%E5%9F%BA%E4%BA%8E%20k8s%E5%81%9A%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/">如何基于 k8s做私有化部署</a>
          </li>
        
          <li>
            <a href="/2023/12/17/2023/%E4%BA%91%E5%8E%9F%E7%94%9F/10%E4%B8%AA%E5%B8%B8%E8%A7%81%E7%9A%84%20Kubernetes%20%E9%99%B7%E9%98%B1%E5%92%8C%E6%8C%91%E6%88%98/">10个常见的 Kubernetes 陷阱和挑战</a>
          </li>
        
      </ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/AI/" style="font-size: 10px;">AI</a> <a href="/tags/AIGC/" style="font-size: 10px;">AIGC</a> <a href="/tags/Kubernetes/" style="font-size: 17.5px;">Kubernetes</a> <a href="/tags/Stream/" style="font-size: 10px;">Stream</a> <a href="/tags/chatGPT/" style="font-size: 10px;">chatGPT</a> <a href="/tags/eBPF/" style="font-size: 10px;">eBPF</a> <a href="/tags/java/" style="font-size: 15px;">java</a> <a href="/tags/k8s/" style="font-size: 12.5px;">k8s</a> <a href="/tags/k8s10-%E4%B8%AA%E5%B8%B8%E8%A7%81%E6%8C%91%E6%88%98%E5%92%8C%E9%99%B7%E9%98%B1/" style="font-size: 10px;">k8s10 个常见挑战和陷阱</a> <a href="/tags/nio/" style="font-size: 10px;">nio</a> <a href="/tags/%E4%BB%80%E4%B9%88%E6%98%AFeBPF/" style="font-size: 10px;">什么是eBPF</a> <a href="/tags/%E4%BB%8Edocker%E5%88%B0k8s/" style="font-size: 10px;">从docker到k8s</a> <a href="/tags/%E5%88%86%E5%B8%83%E5%BC%8F/" style="font-size: 17.5px;">分布式</a> <a href="/tags/%E5%88%86%E5%BA%93%E5%88%86%E8%A1%A8%E5%8F%8A%E4%BA%8B%E5%8A%A1%E4%B8%80%E8%87%B4%E6%80%A7%E8%AE%BE%E8%AE%A1/" style="font-size: 17.5px;">分库分表及事务一致性设计</a> <a href="/tags/%E5%8F%AF%E8%A7%82%E6%B5%8B%E9%A2%86%E5%9F%9F%E5%BA%95%E5%B1%82%E6%8A%80%E6%9C%AF/" style="font-size: 10px;">可观测领域底层技术</a> <a href="/tags/%E5%90%8E%E7%AB%AF/" style="font-size: 10px;">后端</a> <a href="/tags/%E5%A6%82%E4%BD%95%E5%9F%BA%E4%BA%8E-k8s%E5%81%9A%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/" style="font-size: 10px;">如何基于 k8s做私有化部署</a> <a href="/tags/%E5%B9%B6%E5%8F%91/" style="font-size: 15px;">并发</a> <a href="/tags/%E6%9E%B6%E6%9E%84%E6%88%90%E9%95%BF%E6%8C%87%E5%8D%97/" style="font-size: 20px;">架构成长指南</a> <a href="/tags/%E7%A7%81%E6%9C%89%E5%8C%96%E4%BA%A4%E4%BB%98/" style="font-size: 10px;">私有化交付</a> <a href="/tags/%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/" style="font-size: 12.5px;">私有化部署</a> <a href="/tags/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2%E6%9E%B6%E6%9E%84%E6%BC%94%E8%BF%9B/" style="font-size: 10px;">系统部署架构演进</a> <a href="/tags/%E9%93%BE%E8%A1%A8/" style="font-size: 12.5px;">链表</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-classify"></i> 分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/%E4%BA%91%E5%8E%9F%E7%94%9F/">云原生</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%90%8E%E7%AB%AF/">后端</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B7%A5%E5%85%B7/">工具</a><span class="category-list-count">1</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%B7%A5%E5%85%B7/AI/">AI</a><span class="category-list-count">1</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%AE%97%E6%B3%95/">算法</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-archive"></i>公众号</h3>
    <div class="widget">
       <img src="/gzh.jpg" style="width:80%; height:80%;" />
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/AI/" rel="tag">AI</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/AIGC/" rel="tag">AIGC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Kubernetes/" rel="tag">Kubernetes</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Stream/" rel="tag">Stream</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/chatGPT/" rel="tag">chatGPT</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/eBPF/" rel="tag">eBPF</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/" rel="tag">java</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/k8s/" rel="tag">k8s</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/k8s10-%E4%B8%AA%E5%B8%B8%E8%A7%81%E6%8C%91%E6%88%98%E5%92%8C%E9%99%B7%E9%98%B1/" rel="tag">k8s10 个常见挑战和陷阱</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nio/" rel="tag">nio</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%BB%80%E4%B9%88%E6%98%AFeBPF/" rel="tag">什么是eBPF</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%BB%8Edocker%E5%88%B0k8s/" rel="tag">从docker到k8s</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%88%86%E5%B8%83%E5%BC%8F/" rel="tag">分布式</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%88%86%E5%BA%93%E5%88%86%E8%A1%A8%E5%8F%8A%E4%BA%8B%E5%8A%A1%E4%B8%80%E8%87%B4%E6%80%A7%E8%AE%BE%E8%AE%A1/" rel="tag">分库分表及事务一致性设计</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8F%AF%E8%A7%82%E6%B5%8B%E9%A2%86%E5%9F%9F%E5%BA%95%E5%B1%82%E6%8A%80%E6%9C%AF/" rel="tag">可观测领域底层技术</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%90%8E%E7%AB%AF/" rel="tag">后端</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%A6%82%E4%BD%95%E5%9F%BA%E4%BA%8E-k8s%E5%81%9A%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/" rel="tag">如何基于 k8s做私有化部署</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%B6%E5%8F%91/" rel="tag">并发</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9E%B6%E6%9E%84%E6%88%90%E9%95%BF%E6%8C%87%E5%8D%97/" rel="tag">架构成长指南</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%A7%81%E6%9C%89%E5%8C%96%E4%BA%A4%E4%BB%98/" rel="tag">私有化交付</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%A7%81%E6%9C%89%E5%8C%96%E9%83%A8%E7%BD%B2/" rel="tag">私有化部署</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%B3%BB%E7%BB%9F%E9%83%A8%E7%BD%B2%E6%9E%B6%E6%9E%84%E6%BC%94%E8%BF%9B/" rel="tag">系统部署架构演进</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%93%BE%E8%A1%A8/" rel="tag">链表</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-link"></i> 友情链接</h3>
    <div class="widget">
      <ul>
      
        <li>
          <a target="_blank" rel="noopener" href="https://juejin.cn/user/1292681402913080">我的掘金</a>
        </li>
      
        <li>
          <a target="_blank" rel="noopener" href="https://www.zhihu.com/people/dong-wei-zhao-73">我的知乎</a>
        </li>
      
        <li>
          <a target="_blank" rel="noopener" href="https://blog.csdn.net/dweizhao?type=blog">我的CSDN</a>
        </li>
      
      </ul>
    </div>
  </div>


  
</aside>
        
      </div>
      <a id="totop" href="#top"></a>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      <p>
        <a href="/sitemap.xml">网站地图</a>
        <span> | </span><a href="/atom.xml">订阅本站</a>
        <span> | </span><a href="/about/">联系博主</a>
      </p>
      
        <p>
          <i class="fa fa-visitors"></i>
          <i id="busuanzi_container_site_uv"><i id="busuanzi_value_site_uv"></i></i>
          ，
          <i class="fa fa-views"></i>
          <i id="busuanzi_container_site_pv"><i id="busuanzi_value_site_pv"></i></i>
        </p>
      
      <p>
        <span>Copyright &copy; 2023 架构成长指南.</span>
        <span>Theme by <a href="https://github.com/chaooo/hexo-theme-BlueLake/" target="_blank">BlueLake.</a></span>
        <span>Powered by <a href="https://hexo.io/" target="_blank">Hexo.</a></span>
      </p>
    </div>
  </div>
</footer>

    </div>
  </div>
  
<script src="/js/jquery-3.4.1.min.js"></script>


<script src="/js/search.json.js"></script>


  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>






  
<script src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  
    
<script src="/localshare/js/social-share.js"></script>

    
<script src="/localshare/js/qrcode.js"></script>

  
  



  

  

  

  

  

  

  

  
  





</body>
</html>